#ifndef STEELCLIENTAPI_H
#define STEELCLIENTAPI_H

#ifdef _WIN32
    #ifdef STEELCLIENT_EXPORTS
        #define STEELCLIENT_API __declspec(dllexport)
    #else
        #define STEELCLIENT_API __declspec(dllimport)
    #endif
#else
    #define STEELCLIENT_API
#endif

// 包含数据结构定义
#if defined(_WIN64) || defined(__x86_64__) || defined(_M_X64)
typedef unsigned long long SteelClientWindowHandle;
#else
typedef unsigned long SteelClientWindowHandle;
#endif
#include "ConfigData.h"

#ifdef __cplusplus
extern "C" {
#endif

//==============================================================================
// UI控制接口
//==============================================================================

/**
 * @brief 启动UI界面（包含初始化和显示）
 * @param argc 命令行参数个数
 * @param argv 命令行参数数组
 * @param configJson 初始配置数据（JSON字符串，暂支持工况类配置）
 * @return 成功返回0，失败返回-1
 * @note 界面关闭后会自动销毁所有资源
 */
STEELCLIENT_API int startUI(int argc, char* argv[], const char* configJson);

//==============================================================================
// 回调函数类型定义
//==============================================================================

/**
 * @brief 工况类数据变化回调函数
 * @param data 工况类数据指针
 * @param userData 用户自定义数据指针
 */
typedef void (*WorkingConditionCallback)(NavTreeIndex index, const ConfigWorkingConditionData* data, void* userData);

/**
 * @brief 氧枪类数据变化回调函数
 * @param data 氧枪类数据指针
 * @param userData 用户自定义数据指针
 */
typedef void (*OxygenLanceCallback)(NavTreeIndex index, const ConfigOxygenLanceData* data, void* userData);

/**
 * @brief 物料类数据变化回调函数
 * @param data 物料类数据指针
 * @param userData 用户自定义数据指针
 */
typedef void (*MaterialCallback)(NavTreeIndex index, const ConfigMaterialData* data, void* userData);

/**
 * @brief 登录验证回调函数
 * @param username 用户名
 * @param password 密码
 * @param errorMessage 错误消息输出缓冲区（可选，可为nullptr）
 * @param errorMessageSize 错误消息缓冲区大小
 * @param userData 用户自定义数据指针
 * @return 登录成功返回true，失败返回false
 */
typedef bool (*LoginCallback)(const char* username, const char* password, char* errorMessage, int errorMessageSize, void* userData);

typedef void (*MainPageWorkingConditionCallback)(NavTreeIndex index, const MainPageWorkingConditionData* data, void* userData);
typedef void (*MainPageMaterialCallback)(NavTreeIndex index, const MainPageMaterialData* data, void* userData);
typedef void (*MainPageOxygenLanceCallback)(NavTreeIndex index, const MainPageOxygenLanceData* data, void* userData);
typedef void (*MainPageBlowingCallback)(NavTreeIndex index, const MainPageBlowingData* data, void* userData);
typedef void (*MainPageChartCallback)(NavTreeIndex index, const MainPageChartData* data, void* userData);
typedef void (*MainPageOperStageCallback)(NavTreeIndex index, const MainPageOperStageData* data, void* userData);
typedef void (*MainPageOperTotalCallback)(NavTreeIndex index, const MainPageOperTotalData* data, void* userData);
typedef void (*MainPageProcessCallback)(NavTreeIndex index, const MainPageProcessData* data, void* userData);
typedef void (*MainPageVideoCallback)(NavTreeIndex index, const MainPageVideoData* data, void* userData);
typedef void (*MainPageVideoWindowHandleCallback)(NavTreeIndex index, SteelClientWindowHandle handle, void* userData);
typedef void (*ApplicationShutdownCallback)(void* userData);

/**
 * @brief 调试按钮类型枚举
 */
enum DebugButtonType {
    DebugButtonBackBlow = 0,           // 后吹
    DebugButtonBGun = 1,              // B枪
    DebugButtonReturnDrySlight = 2,   // 返干—轻微
    DebugButtonReturnDrySevere = 3,   // 返干—重度
    DebugButtonTopSpray = 4,          // 顶喷
    DebugButtonDoubleSlag = 5         // 双渣
};

/**
 * @brief DebugWidget按钮点击回调函数
 * @param buttonType 按钮类型（DebugButtonType枚举值）
 * @param isPressed 按钮是否被按下（true=按下，false=释放）
 * @param userData 用户自定义数据指针
 */
typedef void (*DebugButtonCallback)(int buttonType, bool isPressed, void* userData);

//==============================================================================
// 回调注册接口
//==============================================================================

/**
 * @brief 注册工况类数据变化回调
 * @param callback 回调函数指针
 * @param userData 用户自定义数据指针
 * @return 回调ID（用于注销），失败返回-1
 */
STEELCLIENT_API int registerWorkingConditionCallback(WorkingConditionCallback callback, void* userData);

/**
 * @brief 注册氧枪类数据变化回调
 * @param callback 回调函数指针
 * @param userData 用户自定义数据指针
 * @return 回调ID（用于注销），失败返回-1
 */
STEELCLIENT_API int registerOxygenLanceCallback(OxygenLanceCallback callback, void* userData);

/**
 * @brief 注册物料类数据变化回调
 * @param callback 回调函数指针
 * @param userData 用户自定义数据指针
 * @return 回调ID（用于注销），失败返回-1
 */
STEELCLIENT_API int registerMaterialCallback(MaterialCallback callback, void* userData);

/**
 * @brief 注册登录验证回调
 * @param callback 回调函数指针
 * @param userData 用户自定义数据指针
 * @return 回调ID（用于注销），失败返回-1
 */
STEELCLIENT_API int registerLoginCallback(LoginCallback callback, void* userData);

/**
 * @brief 注册主界面工况数据变化回调
 */
STEELCLIENT_API int registerMainPageWorkingConditionCallback(MainPageWorkingConditionCallback callback, void* userData);

/**
 * @brief 注册主界面料仓数据变化回调
 */
STEELCLIENT_API int registerMainPageMaterialCallback(MainPageMaterialCallback callback, void* userData);

/**
 * @brief 注册主界面氧枪数据变化回调
 */
STEELCLIENT_API int registerMainPageOxygenLanceCallback(MainPageOxygenLanceCallback callback, void* userData);

/**
 * @brief 注册主界面吹炼数据变化回调
 */
STEELCLIENT_API int registerMainPageBlowingCallback(MainPageBlowingCallback callback, void* userData);

/**
 * @brief 注册主界面曲线数据变化回调
 */
STEELCLIENT_API int registerMainPageChartCallback(MainPageChartCallback callback, void* userData);

/**
 * @brief 注册主界面操作进程阶段数据变化回调
 */
STEELCLIENT_API int registerMainPageOperStageCallback(MainPageOperStageCallback callback, void* userData);

/**
 * @brief 注册主界面总量分物料数据变化回调
 */
STEELCLIENT_API int registerMainPageOperTotalCallback(MainPageOperTotalCallback callback, void* userData);

/**
 * @brief 注册主界面冶炼进程数据变化回调
 */
STEELCLIENT_API int registerMainPageProcessCallback(MainPageProcessCallback callback, void* userData);

/**
 * @brief 注册主界面视频监控数据变化回调
 */
STEELCLIENT_API int registerMainPageVideoCallback(MainPageVideoCallback callback, void* userData);
STEELCLIENT_API int registerMainPageVideoWindowHandleCallback(MainPageVideoWindowHandleCallback callback, void* userData);
STEELCLIENT_API int registerApplicationShutdownCallback(ApplicationShutdownCallback callback, void* userData);

/**
 * @brief 注册DebugWidget按钮点击回调
 * @param callback 回调函数指针
 * @param userData 用户自定义数据指针
 * @return 回调ID（用于注销），失败返回-1
 */
STEELCLIENT_API int registerDebugButtonCallback(DebugButtonCallback callback, void* userData);

/**
 * @brief 注销回调函数
 * @param callbackId 回调ID
 * @return 成功返回0，失败返回-1
 */
STEELCLIENT_API int unregisterCallback(int callbackId);

//==============================================================================
// 主界面数据接口
//==============================================================================

STEELCLIENT_API void setMainPageWorkingConditionData(NavTreeIndex index, const MainPageWorkingConditionData& data);
STEELCLIENT_API bool getMainPageWorkingConditionData(NavTreeIndex index, MainPageWorkingConditionData& out);
STEELCLIENT_API void setMainPageWorkingConditionItem(NavTreeIndex index, int itemIndex, const char* name, const char* value);

STEELCLIENT_API void setMainPageMaterialData(NavTreeIndex index, const MainPageMaterialData& data);
STEELCLIENT_API bool getMainPageMaterialData(NavTreeIndex index, MainPageMaterialData& out);
STEELCLIENT_API void setMainPageMaterialItem(NavTreeIndex index, int itemIndex, const char* name, const char* value);

STEELCLIENT_API void setMainPageOxygenLanceData(NavTreeIndex index, const MainPageOxygenLanceData& data);
STEELCLIENT_API bool getMainPageOxygenLanceData(NavTreeIndex index, MainPageOxygenLanceData& out);
STEELCLIENT_API void setMainPageOxygenLanceField(NavTreeIndex index, const char* fieldName, double value);

STEELCLIENT_API void setMainPageBlowingData(NavTreeIndex index, const MainPageBlowingData& data);
STEELCLIENT_API bool getMainPageBlowingData(NavTreeIndex index, MainPageBlowingData& out);
STEELCLIENT_API void setMainPageBlowingField(NavTreeIndex index, const char* fieldName, const char* value);

STEELCLIENT_API void setMainPageChartData(NavTreeIndex index, const MainPageChartData& data);
STEELCLIENT_API bool getMainPageChartData(NavTreeIndex index, MainPageChartData& out);
STEELCLIENT_API bool getMainPageChartTableData(NavTreeIndex index, MainPageChartTableData& out);
STEELCLIENT_API void setMainPageChartTableData(NavTreeIndex index, const MainPageChartTableData& data);
STEELCLIENT_API void setMainPageChartTableItem(NavTreeIndex index, int row, int column, const char* value);
STEELCLIENT_API void setMainPageOperStageData(NavTreeIndex index, const MainPageOperStageData& data);
STEELCLIENT_API bool getMainPageOperStageData(NavTreeIndex index, MainPageOperStageData& out);
STEELCLIENT_API void setMainPageOperStageItem(NavTreeIndex index, int row, int column, const char* value);
STEELCLIENT_API void setMainPageOperTotalData(NavTreeIndex index, const MainPageOperTotalData& data);
STEELCLIENT_API bool getMainPageOperTotalData(NavTreeIndex index, MainPageOperTotalData& out);
STEELCLIENT_API void setMainPageOperTotalItem(NavTreeIndex index, int row, int column, const char* value);
STEELCLIENT_API void setMainPageProcessData(NavTreeIndex index, const MainPageProcessData& data);
STEELCLIENT_API bool getMainPageProcessData(NavTreeIndex index, MainPageProcessData& out);
STEELCLIENT_API void setMainPageVideoData(NavTreeIndex index, const MainPageVideoData& data);
STEELCLIENT_API bool getMainPageVideoData(NavTreeIndex index, MainPageVideoData& out);

/**
 * @brief 获取主界面视频容器窗口句柄
 * @return 成功返回窗口句柄，失败返回0
 */
STEELCLIENT_API SteelClientWindowHandle getMainPageVideoWindowHandle();

/**
 * @brief 设置VideoWidget中按钮显示模式
 * @param index 炉子索引（NavTreeIndex，如Main_1, Main_2等）
 * @param mode 按钮显示模式（0=显示两个按钮，1=只显示正常按钮，2=只显示异常按钮）
 * @return 成功返回0，失败返回-1
 */
STEELCLIENT_API int setVideoWidgetButtonDisplayMode(NavTreeIndex index, int mode);

//==============================================================================
// 配置界面数据接口
//==============================================================================

/**
 * @brief 设置工况类铁水数据
 * @param index 配置索引（NavTreeIndex，如Config_1, Config_2等）
 * @param moltenIron 铁水成分数据
 * @return 成功返回0，失败返回-1
 * @note 此接口会更新工况类数据中的铁水部分，并触发WorkingConditionCallback回调
 */
STEELCLIENT_API int setSmeltingConfigMoltenIronData(NavTreeIndex index, const ConfigWorkingConditionData::MoltenIronComposition& moltenIron);

#ifdef __cplusplus
}
#endif

#endif // STEELCLIENTAPI_H
